package com.open.capacity.paper.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.log.annotation.LogAnnotation;
import com.open.capacity.paper.service.PaperRecordService;
import com.open.capacity.paper.vo.PaperRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author liangd
 * @since 2021-02-24 15:10
 */
@Api(tags = "问卷记录")
@RestController
@RequestMapping("/paperRecord")
public class PaperRecordController {
    @Autowired
    private PaperRecordService paperRecordService;

    /**
     * 模糊查询
     */
    @GetMapping("/getPaperRecords")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置",required = true, dataType = "Integer")
    })
    @ApiOperation(value = "查询所有问卷记录")
    @LogAnnotation(module = "paper-center")
    public PageResult<PaperRecordVo> getPaperRecords(@RequestParam Map<String, Object> params) throws ControllerException {
        try {
            return paperRecordService.getPaperRecords(params);
        } catch (Exception e) {
            throw new ControllerException(e);
        }
    }

    /**
     * 逻辑删除
     */
    @DeleteMapping("/delete")
    @LogAnnotation(module = "paper-center")
    @ApiOperation(value = "删除问卷记录")
    public Result delete(@RequestParam Integer pareid,@RequestParam Long userid) throws ControllerException {
        try {
            return paperRecordService.deletePaperRecord(pareid,userid);
        } catch (Exception e) {
            throw new ControllerException(e);
        }
    }
}
